<%@page import="entities.MetaSeo"%>
<%@page import="entities.SiteConfig"%>
<%@page import="systems.ConfigSystem"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.Category"%>
<%@page import="entities.User"%>
<%@page import="java.util.Map"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.Article"%>
<%@page import="java.util.List"%>
<%
SiteConfig siteConfig = ConfigSystem.getConfigs();

String name = (String) request.getAttribute("name");
List<Article> articles = (List<Article>) request.getAttribute("articles"); 
Map<String, User> authors = (Map<String, User>) request.getAttribute("authors");
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories");
User author = null;
Category category = null;

//Paginator
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
LanguageHelper translate = (LanguageHelper) request.getAttribute("translate");

MetaSeo metaseo = (MetaSeo) request.getAttribute("metaseo");

//Set content for Seo
Map<String, String> replates = new TreeMap<String, String>();
replates.put("__SERVER_NAME__", UrlHelper.getDomainServer(request));
replates.put("__SERVER_URL__", UrlHelper.getServerUrl(request));
replates.put("__TAG_NAME__", name);

String title = StringHelper.replateContent(metaseo.getTitle(), replates);
String description = StringHelper.replateContent(metaseo.getDescription(), replates);
String keywords = StringHelper.replateContent(metaseo.getKeywords(), replates);
String url = StringHelper.replateContent(metaseo.getOgurl(), replates);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/templates/classic/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="keywords" value="<%=keywords %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=url %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

		<div id="wrapper">
			<div id="page-title">
				<div id="page-title-inner">
					<div class="container">
						<h2>Tag: <%=name %></h2>
					</div>
				</div>	
			</div>
		
			<div class="row-fluid">
				<div class="span8 left-content">
					<% 
	                for (int i = 0; i < articles.size(); i++) {
	                	category = categories.get(articles.get(i).getCategory());
	                	author = authors.get(articles.get(i).getCreator());
	                %>
					<article>
						<div class="date-info">
							<span class="day"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "dd") %></span>
							<span class="month-year"><%=DateHelper.getStringFromDate(articles.get(i).getCreated(), "MMM, yyyy") %></span>
						</div>
						<div class="article-info">
							<div class="article-title">
								<h2><a href="/article/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a></h2>
							</div>
						</div>
						<div class="article-meta">
							<span><i class="icon-user"></i> By 
								<% if (author != null) { %>
		                        &nbsp;<a href="/author/<%=author.getId()%>" itemprop="author"><%=author.getName() %></a> | 
		                        <% } else if (!articles.get(i).getAuthorName().isEmpty()) { %>
		                        &nbsp;<%=articles.get(i).getAuthorName() %> | 
		                        <% } %>
							</span> 
							<span><i class="icon-folder-open"></i> <a href="/category/<%=category.getAlias() %>"><%=category.getName() %></a></span>
							<span class="pull-right">
								<a class="article-entry" href="/article/<%=articles.get(i).getAlias() %>">Read More...</a>
							</span>
						</div>
						<div class="article-desc">
							<p>
								<%=StringHelper.cutString(StringHelper.html2text(articles.get(i).getContent()), 40) %>...
							</p>
						</div>
						
					</article>
					<% } %>
					
				</div>
				
				<jsp:include page="/templates/classic/elements/right.jsp" />
				
			</div>
		</div>
	
<jsp:include page="/templates/classic/layouts/footer.jsp" />